local jianqi = fk.CreateSkill {
  name = "rmt__jianqi",
}

Fk:loadTranslationTable{
  ["rmt__jianqi"] = "荐戚",
  [":rmt__jianqi"] = "每局游戏限三次，出牌阶段，你可以选择一种变更规则并令一名角色按此规则变更武将牌。"..
  "<br>*变更规则：1.从三张同势力武将牌中选择一张；2.替换武将牌为武将牌堆中首张同势力武将。",

  ["#rmt__jianqi"] = "荐戚：你可以令一名角色变更武将牌",
  ["rmt__jianqi_choose"] = "从三张同势力武将牌中选择一张",
  ["rmt__jianqi_top"] = "替换为武将牌堆中首张同势力武将",

  ["$rmt__jianqi"] = "妾身蒲柳，幸得君王恩遇。",
}

jianqi:addEffect("active", {
  anim_type = "control",
  prompt = "#rmt__jianqi",
  card_num = 0,
  target_num = 1,
  interaction = function(self)
    return UI.ComboBox { choices = {"rmt__jianqi_choose", "rmt__jianqi_top"} }
  end,
  times = function (self, player)
    return 3 - player:usedSkillTimes(jianqi.name, Player.HistoryGame)
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(jianqi.name, Player.HistoryGame) < 3
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local to = effect.tos[1]
    local generals = table.filter(room.general_pile, function(name)
      return Fk.generals[name].kingdom == to.kingdom
    end)
    if #generals == 0 then return end
    local general = generals[1]
    if self.interaction.data == "rmt__jianqi_choose" then
      general = room:askToChooseGeneral(to, {
      generals = table.random(generals, 3),
      n = 1,
      no_convert = true,
    })
    end
    room:findGeneral(general)
    room:changeHero(to, general, false, false, true, true)
  end,
})

return jianqi
